package com.example.dto;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;

import java.io.IOException;

public class ClientSettingsDeserializer extends JsonDeserializer<ClientSettingsDTO> {

    @Override
    public ClientSettingsDTO deserialize(JsonParser p, DeserializationContext ctxt)
            throws IOException, JsonProcessingException {
        // 读取 JSON 节点
        JsonNode node = p.getCodec().readTree(p);

        // 创建 DTO 对象
        ClientSettingsDTO dto = new ClientSettingsDTO();
        dto.setRequireProofKey(node.get("settings.client.require-proof-key").asBoolean());
        dto.setRequireAuthorizationConsent(node.get("settings.client.require-authorization-consent").asBoolean());

        return dto;
    }
}